(function(win){
	var document = win.document;
	if(typeof Array.prototype.search == 'undefined'){
		Array.prototype.search = function(item){
			var l = this.length,i;
			for(i = 0; i < l; i++){
				if(this[i] == item){
					return i;
				}
			}
			return -1;
		};
	}

	Array.prototype.del = function(index){
		var length = this.length;
		return this.slice(0, index).concat(this.slice(index+1, length));
	};

	Array.prototype.remove = function(item){
		var index = this.search(item);
		if(index > -1){
			return this.del(index);
		}
		return this;
	};

	String.prototype.stripTags = function(){
		return this.replace(/(?:<[^<]+>|(?:&nbsp){2,}|\s+)/g,'');
	};

	String.prototype.thumbnail = function(subfix){
		return this.replace(/\.(\w+)$/i,subfix+'.$1');
	};
	
	String.prototype.parse = function(o,f){
		if(o.constructor == String || o.constructor == Number){
			return this.replace(/\${([\w\d]+?)}/g,o);
		}else{
			return this.replace(/\${([\w\d]+?)}/g,function(){
				return o[arguments[1]]!=undefined?o[arguments[1]]:(f==undefined?arguments[0]:f);
			});
		}
	};

	if(typeof String.prototype.trim == 'undefined'){
		String.prototype.trim = function(){
			return this.replace(/(:?^\s*|\s*$)/g,'');
		};
	}
	/*
	Function.prototype.method = function(name, func){
		this.prototype[name] = func;
		return this;
	};

	Function.method('inherits', function(parent){
		this.prototype = new parent();
		var d = {},
			p = this.prototype;
		this.prototype.constructor = parent;
		this.method('uber', function uber(name){
			if(!(name in d)) {
				d[name] = 0;
			}
			var f, r, t = d[name], v = parent.prototype;
			if(t) {
				while(t) {
					v = v.constructor.prototype;
					t -= 1;
				}
				f = v[name];
			} else {
				f = p[name];
				if(f == this[name]){
					f = v[name];
				}
			}
			
			d[name] += 1;
			r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
			d[name] -= 1;
			return r;
		});
		
		return this;
	});
	
	Function.method('swiss', function(parent){
		for(var i = 1, l = arguments.length; i < l; i++){
			var name = arguments[i];
			this.prototype[name] = parent[name];
		}
		return this;
	});
	*/
	win.Z = {
		'production' : true,
		'version' : '1.0.0',
		'url' : function(url){
			if(/^http\:\/\/.*$/.test(url))
				return url;
			return SITE_URL+((/.*\..*/.test(url))?'':'index.html')+url;
		},
		'scripts' : [],
		'loadScript' : function(sources, callback) {
			var multiple = (sources.constructor == Array);
			var source = multiple? sources.shift() : sources;
			var callee = arguments.callee;
			var script = document.createElement('script');
			var loaded = function(callback){
				if(script.readyState){
					script.onreadystatechange = function(){
						if(script.readyState == 'loaded' || script.readyState == 'complete'){
							script.onreadystatechange = null;
							callback();
						}
					};
				}else{
					script.onload = callback;
				}

				script.type = 'text/javascript';
				script.src = Z.url('js/' + source + '.js?v=') + win.version;
				document.getElementsByTagName('head').item(0).appendChild(script);
			};
			
			if(Z.scripts.search(source) < 0) {
				if(multiple && sources.length){
					loaded(function(){callee(sources, callback);});
				}else{
					loaded(callback);
				}
				Z.scripts.push(source);	
			} else {
				console.warn(source + ' reload');
				if(multiple && sources.length){
					callee(sources, callback);
				}else{
					callback();
				}
			}
		},
		'log' : function(){
			if(typeof console !== 'undefined'){
				console.log.apply(console, arguments);
			}
		}
	};
	
	
})(window);